import request from '@/utils/request'

/**
 * 加入购物车
 * goodsId    => 商品id     iphone8
 * goodsSkuId => 商品规格id  红色的iphone8  粉色的iphone8
 */
export const addCart = (goodsId, goodsNum, goodsSkuId) => {
  return request.post('/cart/add', {
    goodsId, // 商品id
    goodsNum, // 商品数量
    goodsSkuId // sku
  })
}

/**
 * 获取购物车列表的后端接口
 */
export const getCartList = () => {
  return request.get('/cart/list')
}

/**
 * 更新购物车商品数量的后端接口
 */
export const changeCount = (goodsId, goodsNum, goodsSkuId) => {
  return request.post('/cart/update', {
    goodsId,
    goodsNum,
    goodsSkuId
  })
}

/**
 * 删除购物车商品
 * 传入的这个id是购物车记录的唯一id
 */
export const delSelect = (cartIds) => {
  return request.post('/cart/clear', 
    cartIds
  )
}
